package exp.eval;

import java.io.File;
import java.util.ArrayList;
import java.util.TreeMap;

import tools.FileReaderEnhance;
import tools.ObjectTools;
import tools.similarity.RougeN;

public class EvalHybridTFIDF {
	
	static String goldPath = "data/_newData/gold/";
	static String resultPath = "data/_newData/baseline/HybridTFIDF/";
	static int numOfGold = 20;
	static int numOfTest = 20;
	
	public static void main(String[] args) {
		int N = 1;
		if (args.length > 0) {
			N = Integer.parseInt(args[0]);
		}
		System.out.println("Using ROUGE-" + N);
		
		for (File file : (new File(resultPath)).listFiles()) {
			@SuppressWarnings("unchecked")
			TreeMap<Integer, ArrayList<String>> gold = 
				(TreeMap<Integer, ArrayList<String>>) ObjectTools.readFromFile(goldPath + file.getName());
			StringBuilder goldSum = new StringBuilder();
			int count = 0;
	aaa:		for (Integer key : gold.descendingKeySet()) {
				for (String g : gold.get(key)) {
					goldSum.append(g);
					goldSum.append(' ');
					count++;
					if (count == numOfGold) {
						break aaa;
					}
				}
			}
			String[] goldSummary = new String[1];
			goldSummary[0] = goldSum.toString();
			System.out.println("==================" + file.getName() + "======================");
			String [] result = FileReaderEnhance.readToString(file, "UTF-8").split("\n");
			StringBuilder testSummary = new StringBuilder();
			for (int i = 0; i < numOfTest; i++) {
				testSummary.append(result[i]);
				testSummary.append(' ');
			}
			RougeN r = new RougeN(N, 1);
			r.getRouge().evaluate(testSummary.toString(), goldSummary);
			Double f = r.getRouge().getFScore();
			Double p = r.getRouge().getPrecision();
			Double re = r.getRouge().getRecall();
			System.out.println("Result of ROUGE-" + N + ": ");
			System.out.println("\tPrecition = " + p);
			System.out.println("\tRecall = " + re);
			System.out.println("\tF-score = " + f);
			System.out.println("============================================");
		}
	}
}
